package aclass.rocksea.com.database;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import java.util.ArrayList;
import java.util.List;

import aclass.rocksea.com.database.db.LiteOrmHelper;
import aclass.rocksea.com.database.db.Message;
import aclass.rocksea.com.database.db.Note;
import aclass.rocksea.com.database.db.ScrollListActivity;

public class MainActivity extends AppCompatActivity {

    private LiteOrmHelper mUtil;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Note note1 = new Note("陈2名",0);
        String uuid = note1.getUuid();
        ArrayList<Note.Data> list = new ArrayList<>();
        Note.Data data1 = new Note.Data(uuid,"K1","1");
        Note.Data data2 = new Note.Data(uuid,"K2","2");
        Note.Data data3 = new Note.Data(uuid,"K3","3");
        list.add(data1); list.add(data2);list.add(data3);
        note1.setList(list);

        Message message = new Message("J");
        Message message1 = new Message("D");
        Message message2 = new Message("K");
        mUtil = LiteOrmHelper.initLiteOrm(this);
        mUtil.insert(note1);
        mUtil.insert(message);
        mUtil.insert(message1);
        mUtil.insert(message2);
    }

    public void query(View view){
        List<Note> notes = mUtil.query(Note.class);
        for (Note note : notes) {
            System.out.println(note.getUuid()+"\n"+note.getName());
        }
        List<Message> messageList = mUtil.query(Message.class);
        for (Message message : messageList) {
            System.out.println(message.toString());
        }


        Intent intent = new Intent(this, ScrollListActivity.class);
        startActivity(intent);


    }
}
